home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / CALLMACH.EX < prev    next >
Text File  |  1996-03-10  |  2KB  |  69 lines

  1.         -- Example of calling a machine code 
  2.         -- routine from Euphoria
  3.  
  4. include machine.e
  5. include graphics.e
  6.  
  7. sequence vc
  8. vc = video_config()
  9.  
  10. atom screen
  11. if vc[VC_COLOR] then
  12.     screen = #B8000 -- color
  13. else
  14.     screen = #B0000 -- mono
  15. end if
  16.  
  17. sequence string_copy_code, string
  18. atom code_space, string_space, screen_location
  19.  
  20. clear_screen()
  21.  
  22. string = {'E', BRIGHT_BLUE, 'u', BRIGHT_GREEN, 'p', BRIGHT_CYAN, 
  23.       'h', BRIGHT_RED, 'o', BRIGHT_MAGENTA, 'r', YELLOW,
  24.       'i', BRIGHT_WHITE, 'a', GREEN, '!', BROWN+128}
  25.  
  26. string_space = allocate(length(string)+1)
  27. screen_location = screen + 11*80*2 + 64 -- 11 lines down
  28.  
  29.         -- String Copy machine code:
  30.         -- (will move at least one char)
  31. string_copy_code =
  32.       {#50,                            -- push eax
  33.        #53,                            -- push ebx
  34.        #52,                            -- push edx
  35.        #B8} &                          -- mov eax, 
  36.        int_to_bytes(string_space) &    -- string address (source)
  37.       {#BA} &                          -- mov edx, 
  38.        int_to_bytes(screen_location) & -- screen address (destination)
  39.       {#8A, #18,                       -- L1: mov bl, [eax]
  40.        #40,                            -- inc eax
  41.        #88, #1A,                       -- mov [edx],bl
  42.        #83, #C2, #01,                  -- add edx, #1
  43.        #80, #38, #00,                  -- cmp byte ptr [eax], #00
  44.        #75, #F3,                       -- jne L1
  45.        #5A,                            -- pop edx       
  46.        #5B,                            -- pop ebx
  47.        #58,                            -- pop eax
  48.        #C3}                            -- ret
  49.  
  50. -- poke in the machine code:
  51. code_space = allocate(length(string_copy_code))
  52. poke(code_space, string_copy_code)
  53.  
  54. -- poke in the string:
  55. poke(string_space, string & 0)
  56.  
  57. puts(1, "\n  calling machine code routine ... ")
  58.  
  59. -- call the machine code:
  60. call(code_space) -- copies string to screen
  61.  
  62. -- these would be freed anyway when the program ends:
  63. free(code_space)
  64. free(string_space)
  65.  
  66. puts(1, "success\n")
  67.  
  68.  
  69.